<?php
/// Pictures
function UploadItemFile($itemid)
{
    if(!isset($_FILES['userfile']['name']) || !isset($_FILES['userfile']['size']))
        return false;

    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];

    if ($fileSize <= 0)
        return false;
    if (substr($fileType,0,5) != 'image')
        return false;
    $fp = fopen($tmpName, 'r');
    $content = fread($fp, $fileSize);
    $content = addslashes($content);
    fclose($fp);

    if(!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
    }

    $link = OpenSql();
    $query = "UPDATE items SET imagecontent='$content',imagetype='$fileType',imagesize=$fileSize WHERE id=$itemid";

    mysql_query($query) or die(mysql_error($link));

    CloseSql($link);
	return true;
}

?>
